package ro.romanescu.useradmin.hibernate;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import ro.romanescu.useradmin.IRole;

/**
 * Role class is used to assign multiple rights under a common 'role'.
 */
public class Role implements IRole, Serializable
{
  private long id;
  private String name;
  private String description;
  private Date creationDate;
  private User author;
  private Date lastModificationDate;
  private User lastModificationAuthor;
  private List<Class> rights = new ArrayList<Class>();
  private boolean audit;


  public long getId() {
    return id;
  }
  
  
  public void setId( long id ) {
    this.id = id;
  }


  public void setName( String param ) {
    this.name = param;
  }

  public String getName() {
    return name;
  }

  public void setDescription( String param ) {
    this.description = param;
  }

  public String getDescription() {
    return description;
  }

  public void setCreationDate( Date param ) {
    this.creationDate = param;
  }

  public Date getCreationDate() {
    return creationDate;
  }

  public void setAuthor( User param ) {
    this.author = param;
  }

  public User getAuthor() {
    return author;
  }

  public void setLastModificationDate( Date param ) {
    this.lastModificationDate = param;
  }

  public Date getLastModificationDate() {
    return lastModificationDate;
  }

  public void setLastModificationAuthor( User param ) {
    this.lastModificationAuthor = param;
  }

  public User getLastModificationAuthor() {
    return lastModificationAuthor;
  }

  public void setAudit( boolean param ) {
    this.audit = param;
  }

  public boolean isAudit() {
    return audit;
  }


  public void setRights( List<Class> param ) {
    this.rights = param;
  }

  public List<Class> getRights() {
    return rights;
  }


  @Override
  public boolean equals( Object object ) {
    if( this == object ) {
      return true;
    }
    if( !( object instanceof Role ) ) {
      return false;
    }
    final Role other = ( Role )object;
    if( id != other.id ) {
      return false;
    }
    if( !(name == null ? other.name == null : name.equals(other.name)) ) {
      return false;
    }
    if( !(description == null ? other.description == null : description.equals(other.description)) ) {
      return false;
    }
    if( !(creationDate == null ? other.creationDate == null : creationDate.equals(other.creationDate)) ) {
      return false;
    }
    if( !(author == null ? other.author == null : author.equals(other.author)) ) {
      return false;
    }
    if( !(lastModificationDate == null ? other.lastModificationDate == null : lastModificationDate.equals(other.lastModificationDate)) ) {
      return false;
    }
    if( !(lastModificationAuthor == null ? other.lastModificationAuthor == null : lastModificationAuthor.equals(other.lastModificationAuthor)) ) {
      return false;
    }
    if( !(rights == null ? other.rights == null : rights.equals(other.rights)) ) {
      return false;
    }
    if( audit != other.audit ) {
      return false;
    }
    return true;
  }

  @Override
  public int hashCode() {
    final int PRIME = 37;
    int result = 1;
    result = PRIME * result + (int) (id ^ (id >>> 32));
    result = PRIME * result + ((name == null) ? 0 : name.hashCode());
    result = PRIME * result + ((description == null) ? 0 : description.hashCode());
    result = PRIME * result + ((creationDate == null) ? 0 : creationDate.hashCode());
    result = PRIME * result + ((author == null) ? 0 : author.hashCode());
    result = PRIME * result + ((lastModificationDate == null) ? 0 : lastModificationDate.hashCode());
    result = PRIME * result + ((lastModificationAuthor == null) ? 0 : lastModificationAuthor.hashCode());
    result = PRIME * result + ((rights == null) ? 0 : rights.hashCode());
    result = PRIME * result + (audit ? 0 : 1);
    return result;
  }
}
